﻿using System;
using System.Collections;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CE.Global;
using CE.AreaCountry;

public partial class Admin_area_country_ViewCountry : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/Admin/AdminSecureLogin.aspx");
        }


        if (!Page.IsPostBack)
        {
            //LoadAreaRegion();
            LoadCountries();
        }


    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();
        DataTable _dtCountries = _countryinfodb.SearchCountryInfo(txtCountrySearch.Text.Trim().ToString());

        if (_dtCountries.Rows.Count > 0)
        {
            grvCountryDetails.DataSource = _dtCountries;
            grvCountryDetails.DataBind();
        }

    }

    //private void LoadAreaRegion()
    //{
    //    DataTable _dtArea = General.GetComboItem("RegionArea", false);
    //    ddlAreaRegion.DataSource = _dtArea;
    //    ddlAreaRegion.DataTextField = _dtArea.Columns[0].ColumnName.ToString();
    //    ddlAreaRegion.DataValueField = _dtArea.Columns[1].ColumnName.ToString();
    //    ddlAreaRegion.DataBind();

    //    ddlAreaRegion.Items.Insert(0, new ListItem("Select", "-1"));
    //}

    private void LoadCountries()
    {
        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();
        DataTable _dtCountries = _countryinfodb.GetCountryInfoList();

        if (_dtCountries.Rows.Count > 0)
        {
            grvCountryDetails.DataSource = _dtCountries;
            grvCountryDetails.DataBind();
        }

    }

    protected void grvCountryDetails_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvCountryDetails.Rows.Count > 0)
        {
            string strCoId = grvCountryDetails.SelectedDataKey.Value.ToString();
            Response.Redirect("AddNewCountry.aspx?COId=" + strCoId);
        }
    }

    protected void grvCountryDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvCountryDetails.PageIndex = e.NewPageIndex;
        LoadCountries();
 
    }
}
